﻿using CommonCater;
using Lufei_CaterBLL;
using Lufei_CaterModel;
using Lufei_CaterUI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ItcastCater
{
    public partial class FrmChangeRoom : Form
    {
        public FrmChangeRoom()
        {
            InitializeComponent();
        }

        //修改房间根据id来修改
        public int RoomID { get; set; }


        //给控件赋值
        public void SetValue(object sender,EventArgs e)
        { 
            UpdateMemmberInfo<RoomInfo> ri=e as UpdateMemmberInfo<RoomInfo>;
            if (ri != null)
            {
                //获取房间信息
                RoomInfo roomInfo = ri.obj;
                txtRName.Text= roomInfo.RoomName;
                txtRType.Text = roomInfo.RoomType.ToString();
                txtRMinMoney.Text = roomInfo.RoomMinimunConsume.ToString();
                txtRPerNum.Text = roomInfo.RoomMaxConsumer.ToString();
                txtIsDeflaut.Text = roomInfo.IsDefault.ToString();
                RoomID = roomInfo.RoomId;
            }
        }

        /// <summary>
        /// 修改数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOk_Click(object sender, EventArgs e)
        {
            RoomInfoBLL bll = new RoomInfoBLL();
            //构造房间对象
            RoomInfo roomInfo = new RoomInfo();
            roomInfo.RoomName = txtRName.Text.Trim();
            roomInfo.RoomType = Convert.ToInt32(txtRType.Text.Trim());
            roomInfo.RoomMinimunConsume = Convert.ToDecimal(txtRMinMoney.Text.Trim());
            roomInfo.RoomMaxConsumer = Convert.ToInt32(txtRPerNum.Text.Trim());
            roomInfo.IsDefault = Convert.ToInt32(txtIsDeflaut.Text.Trim());
            roomInfo.RoomId = RoomID;

            bool isUpdate = bll.UpdateRoomById(roomInfo);
            if (isUpdate)
            {
                MessageBox.Show("修改成功!!!");
                log<FrmChangeRoom>.LogError("修改房间成功!!!!");
            }
            else
            {
                MessageBox.Show("修改失败!!!");
                log<FrmChangeRoom>.LogError("修改房间失败!!!!");
            }
        }
    }
}
